package com.jams.goodox.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import java.util.List;

public class DateTimePickerDialog extends AlertDialog implements
		OnClickListener {
	private DateTimePicker mDateTimePicker;
	private OnDateTimeSetListener mOnDateTimeSetListener;
	String date;
	String hours;

	public DateTimePickerDialog(Context context, List<String> dateList,
                                List<String> timeZeroList, List<String> timeNormalList) {
		super(context);
		mDateTimePicker = new DateTimePicker(context, dateList, timeZeroList,
				timeNormalList);
		setView(mDateTimePicker);
		/*
		 * 实现接口，实现里面的方法
		 */
		mDateTimePicker
				.setOnDateTimeChangedListener(new DateTimePicker.OnDateTimeChangedListener() {
					@Override
					public void onDateTimeChanged(DateTimePicker view,
							String date, String hours) {
						setDate(date, hours);
					}
				});

		setButton("确定", this);
		setButton2("取消", (OnClickListener) null);
		setTitle("请选择服务时间");

		setDate(dateList.get(0), timeZeroList.get(0));
	}

	private void setDate(String date, String hours) {
		this.date = date;
		this.hours = hours;
	}

	/*
	 * 接口回調控件 秒数
	 */
	public interface OnDateTimeSetListener {
		void OnDateTimeSet(AlertDialog dialog, String date, String hours);
	}

	/*
	 * 对外公开方法让Activity实现
	 */
	public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
		mOnDateTimeSetListener = callBack;
	}

	public void onClick(DialogInterface arg0, int arg1) {
		if (mOnDateTimeSetListener != null) {
			mOnDateTimeSetListener.OnDateTimeSet(this, date, hours);
		}
	}

	public void setDateTime(String date,String time){
		mDateTimePicker.setDateTime(date,time);
	}

	public void setSelectPosi(int datePosi,int timePosi){
		mDateTimePicker.setSelectPosi(datePosi,timePosi);
	}
}
